package radiowaves;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Semaphore;

import packets.RadioPacket;

public class RadioWaves {
	private final List<RadioPacket> packets = new ArrayList<RadioPacket>();
	private final Semaphore _sem;

	public RadioWaves(Semaphore sem) {
		_sem = sem;
	}

	public void addPacket(RadioPacket p) {
		packets.add(p);
	}

	public void removePacket(RadioPacket p) {
		packets.remove(p);
	}

	public List<RadioPacket> searchForPackets(String destination) {
		List<RadioPacket> destPackets = new ArrayList<RadioPacket>();

		for (RadioPacket p : packets) {
			if (p.getDestination().equals(destination))
				destPackets.add(p);
		}

		return destPackets;
	}

	public Semaphore getSem() {
		return _sem;
	}
}
